package com.shanzhi.connection.common;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;

import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

public class WordToText {


    public static void convertDocxToTxt(String docxPath, String txtPath) {
        try (FileInputStream fis = new FileInputStream(docxPath);
             XWPFDocument document = new XWPFDocument(fis)) {

            List<XWPFParagraph> paragraphs = document.getParagraphs();

            try (FileWriter writer = new FileWriter(txtPath)) {
                for (XWPFParagraph para : paragraphs) {
                    writer.write(para.getText() + "\n");
                }
            }

            System.out.println("转换完成！");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        String docxPath = "D:\\桌面\\成华组织\\AI问答文档(2)\\AI问答文档\\关于印发《成华区2025年“微网实格”治理关爱激励礼遇措施清单》的通知.docx"; // 替换为你的 .docx 文件路径
        String txtPath = "output.txt";    // 输出的 .txt 文件路径

        convertDocxToTxt(docxPath, txtPath);
    }
}
